
package com.zoo.transfer

import com.mongodb.DB
import com.mongodb.DBCursor
import com.mongodb.DBCollection
import com.mongodb.BasicDBObject
import com.mongodb.MongoClient
import com.mongodb.ServerAddress

class MongoDB {

    def updateCustomerTable(obj) {

        def time = System.currentTimeMillis()

        //def addrs = [new ServerAddress("192.168.1.200" , 30001), new ServerAddress("192.168.1.201" , 30002),new ServerAddress("192.168.1.202" , 30003)]
        def mongo = new MongoClient("192.168.1.200" , 30001)
        def db = mongo.getDB("store")
        def table = db.getCollection("customer")

        table.drop()

        //array.email.each { email ->
        //    println "email=${email}"
        //    table.update({email: email},{$set:{}})
        //}

        table.insert(obj)

        //def cursor = table.find([email: "vasil@compuvest.com"] as BasicDBObject)
        def cursor = table.find([eml: "vasil@compuvest.com"] as BasicDBObject)
        while(cursor.hasNext()) {
            println cursor.next()
        }

        obj.put('svt', System.currentTimeMillis() - time)

        return obj.toString()
        /*
        table.update([name: "Vasill"] as BasicDBObject, [$set: [name: "Vasill-updated"]] as BasicDBObject)

        def cursor2 = table.find([name: "Vasill-updated"] as BasicDBObject)
        while(cursor2.hasNext()) {
            println cursor2.next()
        }
*/

    }
/*    db.bios.update(
    { _id: 3 },
    { $set: {
             mbranch: 'Navy',
             'name.aka': 'Amazing Grace'
           }
    }
    )*/


}

    /*
        //print "obj = ${obj}"
        //print "orders = ${orders}"
        //print "objord = ${objord}"
        //def obj = new BasicDBObject(data)
        //print "array = ${array}"
        //print ".email = ${array.email}"
        //print "email[0] = ${array[0].email}"
    private void writeRecordsToMongoDB(final String name,
                        final DBCollection collection, int batchSize) {
                long startTime = System.currentTimeMillis();
                for (int i = 1; i <= batchSize; i++) {
                        BasicDBObject obj = new BasicDBObject();
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("fName", "Shekhar" + i);
                        map.put("lName", "Gulati" + i);
                        map.put("age", String.valueOf(i));
                        map.put("bio", StringUtils.repeat("I am a Java Developer. ", 100));
                        obj.putAll(map);
                        collection.insert(obj);
                }
                long endTime = System.currentTimeMillis();
                double seconds = ((double) (endTime - startTime)) / (1000);
                double rate = batchSize / seconds;
**/
